package com.sun;

import java.util.concurrent.TimeUnit;

/**
 * @Author: Suncl
 * @Date: 2023/4/14 14:59
 */
public class SynchronziedTest03 {
    public static void main(String[] args) {
        Phone phone = new Phone();

        new Thread(()->phone.sendEmail(),"第一个线程  ").start();
        new Thread(()->phone.call(),"第2个线程  ").start();
    }
}

class Phone{

    public synchronized void sendEmail(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "发邮件。。。");
    }

    public  void call(){
        System.out.println(Thread.currentThread().getName() + "打电话。。。");
        sendEmail();
    }
}
